<?php 
set_time_limit(0);
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd  ='';
$dbName ='si';

for ($k=0;$k<3;$k++){
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
    $query=$mysqli->query("select openid from cishu  group by openid  having count(openid) >1 limit 0,1 ");
    if($query->num_rows>0){
        $cishuInfo=$query->fetch_array();
        $openid=$cishuInfo['openid'];
        $query=$mysqli->query("select id,fen from cishu where openid='".$openid."' limit 0,2  ");
        $id=NULL;
        $fen=0;
        while ($list=$query->fetch_array()){
            if (0 == $fen){
                $id=$list['id'];
                $fen=$list['fen'];
            }
            
            if ($fen > $list['fen']){
                $id=$list['id'];
                $fen=$list['fen'];
            }
            //var_dump($list);
            //echo "<br />";
        } 
        
      //  var_dump($openid);
        
        //echo "<br />";
       // echo "<br />";
        //echo $id;
    
        $mysqli->query("delete from cishu where id='".$id."'  ");
    
    }
    $mysqli->close();
    
    $rand=rand(1,100);
    if (10 == $rand){
       // sleep(1);
    }
    
}

echo "<br />";
echo $id;